/**
 *    Copyright 2009-2020 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.Interceptor;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;

import java.util.Properties;

/**
 * 慢sql拦截器
 */
//@Intercepts(@Signature(type = StatementHandler.class, method = , args = ))
public class LowerSqlInterceptor implements Interceptor {

    private long threshold;

    private final long DEFAULT_THRESHOLD = 200;

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        return null;
    }

    /**
     * 生成动态代理并返回
     * @param target
     * @return
     */
    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    /**
     * 初始化属性
     * @param properties
     */
    @Override
    public void setProperties(Properties properties) {
        String thresholdStr = properties.getProperty("threshold");
        if(null == thresholdStr || 0 == thresholdStr.length()) {
            this.threshold = DEFAULT_THRESHOLD;
        } else {
            this.threshold = Long.valueOf(thresholdStr);
        }
    }
}
